![]() |
PATH![]() |
![]() ![]() |
The File Specification class specifies the name and location on disk of a file that may not yet exist. You can obtain a file specification from the New File scripting addition command distributed with AppleScript, or from an application command that returns a file specification. The following statements use the New File command, which displays a standard system dialog to obtain a filename and location from the user.
set fileSpec to new file default name "New Report"
class of fileSpec --result: file specification
The default name displayed is "New Report" and the default directory is the current directory. (The current directory is typically the directory where the application was launched, the directory where the application last opened or saved a previous document, or another directory specified by the application. The current directory may be affected by settings in the General Controls control panel.)
The user can specify any filename and location. This statement stores the returned file specification, which describes the name and location specified by the user, in the variable fileSpec. Depending on what the user specifies, the result in the Script Editor's result window is something like the following:
file "Hard Disk:Desktop Folder:New Report"
You can coerce a file specification to a string, which results in a string containing the full path name to the file:
fileSpec as string --result: "Hard Disk:Desktop Folder:New Report"
Beyond coercing the pathname to a string, you cannot use AppleScript to directly access or manipulate the information in a file specification. However, you can obtain a file specification from, or pass a file specification to, a scripting addition or application that knows how to work with a file specification. For a full example that obtains a file specification and passes it to an application, see Specifying a File by File Specification.